package top.lyjwn.todo.mail;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@Configuration
public class MailConfig implements EnvironmentAware {

   private Environment environment;

   @Override
   public void setEnvironment(Environment environment) {
      this.environment =environment;
   }

/*
   public static String MAIL_SMTP_HOST = "nigezhu.top";

   public static Integer MAIL_SMTP_PROT = 465;

   public static String MAIL_USER ="luoyujie@nigezhu.top" ;

   public static String MAIL_PASSWORD = "2953818";

   public static String MAIL_NICKNAME ="临渝软件(官方服务器)";

 */

   @Bean
   public  MailConfigParam getMailConfigParam()
   {
      MailConfigParam mailConfigParam = new MailConfigParam();
      String host = this.environment.getProperty("lyjwn.mail.host");
      mailConfigParam.setHost(host);
      String prot = this.environment.getProperty("lyjwn.mail.prot");
      mailConfigParam.setProt(prot!=null?Integer.parseInt(prot):null);
      String user = this.environment.getProperty("lyjwn.mail.user");
      mailConfigParam.setUser(user);
      String password = this.environment.getProperty("lyjwn.mail.password");
      mailConfigParam.setPassword(password);
      String nickname = this.environment.getProperty("lyjwn.mail.nickname");
      mailConfigParam.setNickname(nickname);
      return  mailConfigParam;
   }
}
